package com.bigluo.service.impl;

import com.bigluo.api.BaseResponse;
import com.bigluo.dao.domain.User;
import com.bigluo.dao.mappers.UserMapper;
import com.bigluo.service.FileUploadService;
import com.bigluo.util.Assert;
import com.bigluo.util.ParseFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;
import java.util.List;

/**
 * Created by luojun on 2017/9/8.
 */
@Service
public class FileUploadServiceImpl implements FileUploadService {
    @Autowired
    private UserMapper userMapper;

    @Transactional
    public BaseResponse dealFile(InputStream inputStream)throws Exception {
        List<User> userList = ParseFileUtil.parseExcel(inputStream,User.class);
        Assert.notEmpty(userList,"上传的Excel文件为空","TMP00005");
        for(User user : userList) {
            userMapper.save(user);
        }
        BaseResponse response = new BaseResponse();
        response.setRspCode("TMP00000");
        response.setRspMsg("处理成功");
        return response;
    }
}
